package com.example.othree.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.othree.entity.PollutionHistoryDataJjjSitesMonth;
import com.example.othree.entity.PollutionHistoryDataJjjSitesSeason;
import com.example.othree.mapper.PollutionHistoryDataJjjSitesSeasonMapper;
import com.example.othree.service.PollutionHistoryDataJjjSitesSeasonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@Service
public class PollutionHistoryDataJjjSitesSeasonServiceImpl extends ServiceImpl<PollutionHistoryDataJjjSitesSeasonMapper, PollutionHistoryDataJjjSitesSeason> implements PollutionHistoryDataJjjSitesSeasonService {

    @Resource
    PollutionHistoryDataJjjSitesSeasonMapper pollutionHistoryDataJjjSitesSeasonMapper;

    @Override
    public List<PollutionHistoryDataJjjSitesSeason> pollutionAnalyzeDataByDate(String startTime, String endTime, String season, String[] cities) {
        return pollutionHistoryDataJjjSitesSeasonMapper.pollutionForSite(Integer.parseInt(startTime), Integer.parseInt(endTime), season, cities);
    }

    @Override
    public List<HashMap<String, String>> pollutionAnalyzeDataByCityForAvg(String startTime, String endTime, String element, String[] cities) {
        return pollutionHistoryDataJjjSitesSeasonMapper.pollutionForSiteByAvea(startTime, endTime, element, cities);
    }

    @Override
    public PollutionHistoryDataJjjSitesSeason pollutionForLevel(String startTime, String endTime, String region, String season) {
        List<PollutionHistoryDataJjjSitesSeason> p = pollutionHistoryDataJjjSitesSeasonMapper.pollutionForLevel(startTime, endTime, new String[]{region});
        for (PollutionHistoryDataJjjSitesSeason i : p){
            if (i.getSeason().equals(season)) return i;
        }
        return null;
    }

    @Override
    public PollutionHistoryDataJjjSitesSeason pollutionForCount(String startTime, String endTime, String region, String season) {
        List<PollutionHistoryDataJjjSitesSeason> p = pollutionHistoryDataJjjSitesSeasonMapper.pollutionForCount(startTime, endTime, new String[]{region});
        for (PollutionHistoryDataJjjSitesSeason i : p){
            if (i.getSeason().equals(season)) return i;
        }
        return null;
    }
}
